# get Tkinter
from Tkinter import *
import Tkinter
import tkMessageBox
from SmallLEDSquareFunc import *


class SmallLEDSquareDraw:
    def doNothing2(self,event):
        self.func.ledSettingBox(self.main)

    # __init__: the initializing function
    #       sets up the SmallLEDSquare widget
    #       when a new widget is created
    #    parameters:
    #       self: the required hidden parameter
    #       master: the widget containing this widget
    #       naming: the name for the SmallLEDSquare
    #       setting: the setting for the duty cycle of the corresponding LED
    def __init__(self,master,mainmaster,naming,setting):
        self.name = StringVar()
        self.dutySetting = IntVar()
        
        self.main = mainmaster # the frame to put LEDSetting in
        self.func = SmallLEDSquareFunc(self) # the functionality connected to this object
        
        # setting up the frames specific to each instance of the
        # SmallLEDSquareDraw class and initializing them
        self.master = master # the frame calling the widget to be created

        # main frame that everything else will be in
        self.mainframe = Frame(self.master, relief=RIDGE, bd=2, height=70, width=70)
        self.mainframe.grid(rowspan=4)
        self.mainframe.grid_propagate(0)

        # setting up inner frames for organization
        self.frame1 = Frame(self.mainframe)
        self.frame2 = Frame(self.mainframe)

        self.mainframe.bind("<Button-1>", self.doNothing2)
        self.frame1.bind("<Button-1>", self.doNothing2)
        self.frame2.bind("<Button-1>", self.doNothing2)
        
        # setting the dimensions to not be changed by the widget manager and packing
        self.frame1.grid()
        self.frame2.grid(row=1,rowspan=3)

        # label of the individual LED
        self.nameLabel = Label(self.frame1, textvariable=self.name, font = ('Calibri', 10))
        self.nameLabel.bind("<Button-1>", self.doNothing2)
        self.name.set(naming)
        self.nameLabel.grid(sticky=NW)
        
        # value of the duty cycle of the LED
        self.hey = "hey!"
        self.dutySetting.set(setting)
        self.dutyString=StringVar()
        self.dutyCycleLabel = Message(self.frame2, textvariable=self.dutyString, font=('Calibri', 16))
        self.dutyCycleLabel.bind("<Button-1>", self.doNothing2)
        self.dutyString.set(str(setting))
        self.dutyCycleLabel.grid(columnspan=4)
        
    # redrawSquare: replaces the name and setting of an LED
    #    parameters:
    #       self: the required hidden parameter
    #       naming: the name for the SmallLEDSquare
    #       setting: the setting for the duty cycle of the corresponding LED
    def redrawSquare(self, naming, setting):
        # label of the individual LED
        self.setName(naming)
        
        # value of the duty cycle of the LED
        self.setDutyCycle(setting)
        

    # basic getter/setter methods
    # the setter methods also set the func object
    def getName(self):
        return self.name.get() # Why?
    
    def setName(self, naming):
        self.name.set(naming)
        self.func.setName(naming)

    def getDutyCycle(self):
        return self.dutySetting.get()

    def setDutyCycle(self, setting):
        self.dutySetting.set(setting)
        self.dutyString.set(str(setting))
        self.func.setDutyCycle(str(setting))

    
    # retSquareFrame: returns the frame containing the whole square,
    #       so as to allow for packing on upper levels
    #   return: the main frame
    def retSquareFrame(self):
        return self.mainframe


